//
//  PopAnimatePresent.swift
//  UIViewDemo
//
//  Created by 劢克科技 on 2019/3/8.
//  Copyright © 2019 劢克科技. All rights reserved.
//

import UIKit

class PopAnimatePresent: PopAnimateBase {
    
}

extension PopAnimatePresent: UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return presentTime
    }
    
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        presentAnimate(transitionContext: transitionContext)
    }
    
    // 弹出动画
    func presentAnimate(transitionContext: UIViewControllerContextTransitioning) {
        // 弹出动画，注意：时长应该统一
        guard let presentView = transitionContext.view(forKey: .to) else { return }
        transitionContext.containerView.addSubview(presentView)
        
        presentView.alpha = 0
        
        UIView.animate(withDuration: presentTime, animations: {
            presentView.alpha = 1
        }) { (_) in
            transitionContext.completeTransition(true)
        }
    }
}
